//我们对 0 到 255 之间的整数进行采样，并将结果存储在数组 count 中：count[k] 就是整数 k 的采样个数。 
//
// 我们以 浮点数 数组的形式，分别返回样本的最小值、最大值、平均值、中位数和众数。其中，众数是保证唯一的。 
//
// 我们先来回顾一下中位数的知识： 
//
// 
// 如果样本中的元素有序，并且元素数量为奇数时，中位数为最中间的那个元素； 
// 如果样本中的元素有序，并且元素数量为偶数时，中位数为中间的两个元素的平均值。 
// 
//
// 
//
// 示例 1： 
//
// 输入：count = [0,1,3,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
//,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
//,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
//,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
//,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
//,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
//,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
//输出：[1.00000,3.00000,2.37500,2.50000,3.00000]
// 
//
// 示例 2： 
//
// 输入：count = [0,4,3,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
//,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
//,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
//,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
//,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
//,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
//,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
//输出：[1.00000,4.00000,2.18182,2.00000,1.00000]
// 
//
// 
//
// 提示： 
//
// 
// count.length == 256 
// 1 <= sum(count) <= 10^9 
// 计数表示的众数是唯一的 
// 答案与真实值误差在 10^-5 以内就会被视为正确答案 
// 
// Related Topics 数学 双指针 概率与统计 
// 👍 21 👎 0

  
package com.zwy.leetCode.editor.cn;
public class StatisticsFromALargeSample{
    public static void main(String[] args) {
        Solution solution = new StatisticsFromALargeSample().new Solution();
        int []arr={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3510,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6718,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,27870,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,35,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,26256,0,0,0,0,9586565,0,0,0,0,0,0,0,2333,0,0,0,0};
        double[] doubles = solution.sampleStats(arr);
        for (double aDouble : doubles) {
            System.out.println(aDouble);
        }
    }
      //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public double[] sampleStats(int[] count) {
        double []res=new double[5];

        double sum=0;
        boolean flag=true;
        int count1=0;
        int max=0;
        boolean isO=false;
        for (int i = 0; i < count.length; i++) {
            if(count[i]!=0&&flag){
                flag=false;
                res[0]=i;
            }
            if(count[i]!=0){
                res[1]=i;
            }
            if(count[i]!=0){
                sum+=(double)i*count[i];
                count1+=count[i];
            }
            if(count[i]>max){
                max=count[i];
                res[4]=i;
            }
        }
        res[2]=sum*1.0/count1;
        if(count1%2==0){
            isO=true;
        }
        int c=0;
        double last=0;
        for (int i = 0; i < count.length; i++) {
            if(count[i]!=0){
                c+=count[i];
                if(isO){
                    if(c>count1/2){
                        if(c-count[i]==count1/2){
                            res[3]=(last+i)/2;
                        }
                          else  res[3]=i;
                        return  res;
                    }
                    else if(c==count1/2){

                    }
                }
                else{
                    if(c>=count1/2+1){
                        res[3]=i;
                        return  res;
                    }
                }
                last=i;
            }


        }
        return res;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}